<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryRef"
          :inline="true"
          v-show="showSearch"
          label-width="100px"
        >
          <el-form-item label="服务商名称" prop="deptName">
            <el-input
              v-model="queryParams.deptName"
              placeholder="请输入服务商名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="服务类型" prop="serviceType">
            <el-select @change="changeService" style="width:100%" v-model="queryParams.serviceType" placeholder="请选择服务类型">
              <el-option label="客户报修抢修" value="客户报修抢修"></el-option>
              <el-option label="线路委托运维" value="线路委托运维"></el-option>
              <el-option label="充电桩运维" value="充电桩运维"></el-option>
              <el-option label="配电室运维" value="配电室运维"></el-option>
              <el-option label="电子化移交" value="电子化移交"></el-option>
              <el-option label="高低压业扩" value="高低压业扩"></el-option>
              <el-option label="带电作业服务" value="带电作业服务"></el-option>
              <el-option label="电气设备预试" value="电气设备预试"></el-option>
              <el-option label="配电设备销售" value="配电设备销售"></el-option>
              <el-option label="临电共享服务" value="临电共享服务"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
            >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['facilitator:service:add']"
            >新增
            </el-button>
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="serviceList"
          row-key="deptId"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <!--      展示表格-->
          <el-table-column width="240" label="服务商" prop="deptName" />
          <el-table-column width="200" label="服务类型" align="center" prop="serviceType" />
<!--          <el-table-column label="法人" align="center" prop="leader" />-->
<!--          <el-table-column label="法人电话" align="center" prop="phone" />-->
          <el-table-column width="300" label="地址" align="center" prop="address" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="200">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="160"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
              >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-plus"
                @click="handleAdd(scope.row)"
              >新增</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>


    <!-- 添加或修改客户报修抢修对话框 -->
   <add-service ref="service"></add-service>
  </div>
</template>

<script>
import VDistpicker from 'v-distpicker'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { delDept, listDept } from '@/api/system/dept'

import { handleTree } from '@/utils/ruoyi'
import addService from '@/views/facilitator/service/addService'

export default {
  name: "Dispatch",
  components: {Treeselect, VDistpicker, addService },
  data() {
    return {
      deptOptions: [], // 部门树选项
      deptName: undefined,   // 部门名称
      btnLoading: false,
      serviceList: [],
      buttonLoading: false,
      loading: true,
      showSearch: true,
      ids: [],
      queryParams: {
        typeId: 3
      },
      serviceType: [],
      deptList: [],
      clickItem: {}
    }
  },
  created() {
    this.getList();
  },
  watch: {},
  methods: {
    changeService(value) {
      this.queryParams.serviceType = this.queryParams.serviceType.join(',')
    },
    /** 查询客户报修抢修列表 */
    // listService也是查询服务商
    getList() {
      this.loading = true;
      listDept(Object.assign(this.queryParams)).then(response => {
        this.loading = false;
        this.serviceList = handleTree(response.data, "deptId");
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryRef");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.service.handleAdd()

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.clickItem = row
      this.$refs.service.handleUpdate()
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.deptName + '"的数据项？').then(function() {
        return delDept(row.deptId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "web/CustomerRepair/export",
        {
          ...this.queryParams,
        },
        `CustomerRepair_${new Date().getTime()}.xlsx`
      );
    },
  }
}
</script>

<style scoped>
::v-deep.BMap_mask {
  height: 300px!important;
}

::v-deep .anchorBL {
  display: none !important;
}
</style>
